<?php

namespace App\Models\MainDB;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class UserAccountLog extends Model
{
    protected $table = 'app_user_account_log';

    protected $primaryKey = 'id';

    public function addLog($user_id, $money, $desc, $type, $source_id = 0, $room_id = 0, $ext = [])
    {
        $time = time();
        $beforeAccount = $ext['before_money'] ?? 0;
        $afterAccount = $ext['after_money'] ?? 0;
        $logData = [
            'user_id' => $user_id,
            'balance_before' => $beforeAccount,
            'balance_after' => $afterAccount,
            'balance_value' => $money,
            'desc' => $desc,
            'symbol' => '-1',
            'scene' => $type,
            'random_code' => serialNumber(9),//未知意义
            'target_user_id' => 0,
            'c_time' => $time,
            'u_time' => $time,
        ];
        $this->insert($logData);
    }

}
